package com.qf.t1;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/*
杨威
2021/9/3
15:44
*/

public class TestConnectDataBase  {

    public static void main(String[] args) throws Exception {
        //1.加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库
        String url = "jdbc:mysql://localhost:3306/schools?useSSL=false&characterEncoding=utf-8";//连接地址字符串，什么技术连接哪个数据库，指定IP+端口
        String user = "root";
        String password = "1234";
        Connection connection = DriverManager.getConnection(url, user, password);//结尾.var 自动接收变量
        Statement statement = connection.createStatement();
        int i = statement.executeUpdate("insert into account values(6005,10000),(6004,2000);");
        ResultSet resultSet = statement.executeQuery("select * from student");
        System.out.println("i = " + i);

        ResultSet resultSet1 = statement.executeQuery("select * from student;");
        resultSet1.next();
        String stu_name = resultSet1.getString("stu_name");
        System.out.println("stu_name = " + stu_name);


        //4.释放资源
        connection.close();
    }

}
